from tools_algorithm import *


class Solution:
    def mergeNodes(self, head: Optional[ListNode]) -> Optional[ListNode]:
        p, node = head, None
        while p.next != None:
            if node is not None:
                node.next = p
            node = p
            p = p.next
            while p.val != 0:
                node.val += p.val
                p = p.next
        node.next = None
        return head
